/**
 * 
 */
package inmobiliaria.frsf.reports.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

import org.springframework.core.io.ClassPathResource;

/**
 * @author Lucas
 * 
 */
public class GestionReporte {

	private static final String REPORTS_LOCATION = "inmobiliaria/frsf/reports/";

	public static void generarReporte(ReportData reportData) throws Exception {

		String reportPath;
		reportPath = REPORTS_LOCATION + reportData.getReportName();
		ClassPathResource cpr = new ClassPathResource(reportPath);
		InputStream in = cpr.getInputStream();
		JasperReport jasperReport = (JasperReport) JRLoader.loadObject(in);

		JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
				reportData.getParameters(), reportData.getDataSource());
		JasperViewer.viewReport(jasperPrint, false);
	}
}
